package com.young.common.client.log.model;

import com.young.interfaces.log.model.LogDTO;
import com.young.interfaces.ums.model.User;

/**
 * 公共的上下文数据对象
 * 存放一些整条链路的公共参数
 *
 * @author wangjy
 * @date 2021/10/23 12:42:53
 */
public class CommonContextDTO {
    /**
     * 当前用户
     */
    private User user;
    /**
     * 业务id
     */
    private String businessId;

    /**
     * 构造公共上下文对象
     *
     * @param logDTO
     * @return
     */
    public static CommonContextDTO build(LogDTO logDTO) {
        CommonContextDTO commonContextDTO = new CommonContextDTO();
        commonContextDTO.user = logDTO.getLoginUser();
        commonContextDTO.businessId = logDTO.getBusinessId();
        return commonContextDTO;
    }

    /**
     * 填充公共属性到日志对象
     *
     * @param logDTO
     */
    public void fillTo(LogDTO logDTO) {
        if (logDTO == null) {
            return;
        }
        if (logDTO.getLoginUser() == null) {
            logDTO.setLoginUser(this.user);
        }
        if (logDTO.getBusinessId() == null) {
            logDTO.setBusinessId(this.businessId);
        }
    }

    public CommonContextDTO() {
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getBusinessId() {
        return businessId;
    }

    public void setBusinessId(String businessId) {
        this.businessId = businessId;
    }
}
